home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / sprtxtrn.sea / Support Tools eXternals 1.2.5 / card_33159.txt < prev    next >
Text File  |  1990-11-13  |  12KB  |  316 lines

  1. -- card: 33159 from stack: in.5
  2. -- bmap block id: 8199
  3. -- flags: 0000
  4. -- background id: 3858
  5. -- name: FileCreationDate
  6. ----- HyperTalk script -----
  7. on HideObjects
  8.   hide cd btn "Try It!"
  9. end HideObjects
  10.  
  11. on ShowObjects
  12.   show cd btn "Try It!"
  13. end ShowObjects
  14.  
  15.  
  16. -- part 1 (button)
  17. -- low flags: 00
  18. -- high flags: A002
  19. -- rect: left=82 top=185 right=219 bottom=175
  20. -- title width / last selected line: 0
  21. -- icon id / first selected line: 0 / 0
  22. -- text alignment: 1
  23. -- font id: 0
  24. -- text size: 12
  25. -- style flags: 8192
  26. -- line height: 16
  27. -- part name: Try it!
  28. ----- HyperTalk script -----
  29. on mouseUp
  30.   global errGlobal
  31.   put FilePath("", "Choose a file please.") into fileName
  32.   if fileName = empty then exit mouseUp
  33.   put FileCreationDate(fileName, "nodialog:errGlobal") into fDate
  34.   if errGlobal Γëá empty then
  35.     answer "Error: ΓÇ£" & errGlobal & "ΓÇ¥"
  36.     put empty into errGlobal
  37.   else
  38.     convert fDate to short date
  39.     answer "ΓÇ£" & fileName & "ΓÇ¥ was created on" && fDate
  40.   end if
  41. end mouseUp
  42.  
  43.  
  44.  
  45.  
  46. -- part contents for background part 38
  47. ----- text -----
  48. 14/50
  49.  
  50. -- part contents for background part 20
  51. ----- text -----
  52. FileCreationDate - An XFCN to return the date a file/folder was created
  53.  
  54. FileCreationDate(pathName, ┬½"noDialog:"errorGlobal┬╗)
  55.  
  56. This XFCN returns the same date you see in the Finder windows.  The date is in seconds from 1904 format.  Pass this value to convert in order to get it into a readable
  57. (humanly readable) form.
  58.  
  59.  
  60. -- part contents for background part 42
  61. ----- text -----
  62. {   File:         FileCreationDate.p}
  63. {}
  64. { FileCreationDate(pathname ┬½,"nodialog"┬╗)                }
  65. { XFCN to return the creation date for the file/folder         }
  66. { specified by the path given in the first parameter.       }
  67. {}
  68. {}
  69. {   Written by:      Anup Murarka         Eric Carlson                         }
  70. {               ALINK:  SKEPTIC       ALINK:  cyNic                   }
  71. {                                   CIS:  76004,3356}
  72. {}
  73. {               We are part of the Support Tools Development Group,                                 }
  74. {               Apple Computer, Inc.                                                                          }
  75. {}
  76. {               please DO NOT contact Mac DTS for support of this code!                                }
  77. {}
  78. {               please DO contact the authors for support of this code!                                 }
  79. {}
  80. {               Send comments, bug reports, requests to any of the above                           }
  81. {               E-mail addresses or to:                                                                      }
  82. {}
  83. {                           (one of us)                                                                  }
  84. {                           Apple Computer, Inc.                                                              }
  85. {                           900 E. Hamilton, Ave.                                                          }
  86. {                           Campbell, CA   95008                                                      }
  87. {                           M/S 72-L                                                                         }
  88. {}
  89. {   Copyright:   ┬⌐ 1989, 1990 by Apple Computer, Inc., all rights reserved.                     }
  90. {}
  91. { written by    : Anup Murarka                                                                           }
  92. { AppleLink  : Skeptic                                                                                  }
  93. { modification history                                                                                    }
  94. {          Date              Initials                                    Comments                                   }
  95. {          ----          ------          --------------------------------------------------------  }
  96. {       8/16/89           akm         first written                                                       }
  97. {       5/23/90           ec            removed upper case converion for A/UX compatibility.       }
  98. {                                           Changed version to 1.1                                      }
  99. {}
  100. unit XFCNUnit;
  101.  
  102. interface
  103.  
  104.     uses
  105.         HyperXCmd;
  106.  
  107.     procedure MAIN (paramPtr: XCmdPtr);
  108.  
  109. implementation
  110.  
  111.     procedure FileCreationDate (paramPtr: XCmdPtr);
  112.     FORWARD;
  113.  
  114.     procedure MAIN (paramPtr: XCmdPtr);
  115.     begin
  116.         FileCreationDate(paramPtr);
  117.     end;
  118.  
  119.     procedure reportToUser (paramPtr: XCmdPtr;
  120.                                     msgStr: str255);
  121. {}
  122. { report something back to the user.  }
  123. { the last parameter (optional) to an external may contain }
  124.  { "noDialog" or "noDialog:GlobalName".  GlobalName is the name }
  125.  { of a HyperTalk global variable into which error messages will be }
  126.  { placed.  we've decided to use this approach to avoid confusing }
  127. { an error message with a valid result being returned from an XFCN. }
  128. {}
  129.         var
  130.             tempStr: str255;
  131.     begin
  132. {check the last param to see if the user requested that}
  133. { we suppress the error dialog }
  134.         ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr);
  135.         UprString(tempStr, true);
  136.         if pos('NODIALOG', tempStr) = 0 then
  137.     { no special error handling specified, throw up a dialog and return the error message }
  138.             begin
  139.                 SendCardMessage(paramPtr, concat('answer "', msgStr, '"'));
  140.                 paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  141.             end
  142.         else if (pos(':', tempStr) > 0) then
  143.     { requested global AND noDialog so we fill in the global and return empty }
  144.             begin
  145.                 tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr));
  146.                                                         { get the name of the HC global  to fill }
  147.                 SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr));
  148.                                                         { and fill it }
  149.                 paramPtr^.returnValue := PasToZero(paramPtr, '');      { return empty }
  150.             end
  151.         else
  152.     { requested noDialog only so we return the error condition as the result }
  153.             paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  154.     end;     { procedure }
  155.  
  156.     function AskedForHelp (paramPtr: XCmdPtr;
  157.                                     syntaxMsg: Str255;
  158.                                     copyrightMsg: Str255): boolean;
  159. {   check to see if the user sent a '?' or a '!' as }
  160. { the only parameter. if so we will respond with }
  161. { the calling syntax or the copyright/version info }
  162. { for this external }
  163. {}
  164.         var
  165.             firstStr: str255;
  166.     begin
  167.         askedForHelp := false;
  168.         if paramPtr^.paramCount = 1 then
  169.             begin
  170.                 ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
  171.                     { what is the first param? }
  172.                 if firstStr = '?' then
  173.                     begin
  174.                         reportToUser(paramPtr, syntaxMsg);
  175.                         askedForHelp := true
  176.                     end  { asked for help }
  177.                 else if firstStr = '!' then
  178.                     begin
  179.                         reportToUser(paramPtr, copyRightMsg);
  180.                         askedForHelp := true
  181.                     end;     { asked for copyright info }
  182.             end;     { one parameter passed }
  183.     end;     { function }
  184.  
  185.     function NumberToString (paramPtr: XCmdPtr;
  186.                                     num: LONGINT): Str255;
  187. { use the toolbox call rather than HC's }
  188.         var
  189.             tempStr: str255;
  190.     begin
  191.         NumToString(num, tempStr);
  192.         NumberToString := tempStr;
  193.     end;
  194.  
  195.     function LongToString (paramPtr: XCmdPtr;
  196.                                     num: LONGINT): Str255;
  197. { why, oh why did dan write this one as a procedure??? }
  198.         var
  199.             tempStr: str255;
  200.     begin
  201.         LongToStr(paramPtr, num, tempStr);
  202.         LongToString := tempStr;
  203.     end;
  204.  
  205.     procedure reportResError (paramPtr: XCmdPtr;
  206.                                     errorNum: integer);
  207.         var
  208.             errMsg, tempName: str255;
  209.     begin
  210.         case errorNum of                   { what caused the problem? }
  211.             -0: 
  212.                 errMsg := 'no error.';
  213.             -36: 
  214.                 errMsg := 'I/O Error.';
  215.             -37: 
  216.                 errMsg := 'bad file name or volume name.';
  217.             -38: 
  218.                 errMsg := 'file not open.';
  219.             -39: 
  220.                 errMsg := 'that file has no resource fork.';
  221.             -42: 
  222.                 errMsg := 'too many files open.';
  223.             -43: 
  224.                 errMsg := 'file not found.';
  225.             -45, -54, -61: 
  226.                 errMsg := 'file locked.';
  227.             -47, -49: 
  228.                 errMsg := 'file is busy.';
  229.             -53: 
  230.                 errMsg := 'that volume is not on line.';
  231.             -108: 
  232.                 errMsg := 'not enough room in heap zone.';
  233.             -120: 
  234.                 errMsg := 'directory not found.';
  235.             -121: 
  236.                 errMsg := 'too many working directories open.';
  237.             -127: 
  238.                 errMsg := 'internal file system error.';
  239.             -192: 
  240.                 errMsg := 'resource not found.';
  241.             -193: 
  242.                 errMsg := 'file not found.';
  243.             otherwise
  244.                 errMsg := concat('unexpected error #', NumberToString(paramPtr, errorNum));
  245.         end;         { case }
  246.  
  247.         errMsg := concat('Sorry, ', errMsg);
  248.         reportToUser(paramPtr, errMsg);
  249.         { return the error message }
  250.     end;         { function }
  251.  
  252.     function getParams (paramPtr: XCmdPtr;
  253.                                     var PathToFile: str255): boolean;
  254.     { function to get the parameters and validate them.  Returns boolean}
  255.     { instructing the main procedure to continue if the parameters passed}
  256.     { are valid.  Also returns syntax messages if requested by the user.}
  257.         var
  258.             numParams: integer;
  259.             syntaxStr, copyrightStr: str255;
  260.  
  261.     begin
  262.         getParams := true;     {Initially, assume the parameters are valid.}
  263.         syntaxStr := 'FileCreationDate(pathname ┬½, ΓÇ£nodialogΓÇ¥:errGlobal)';
  264.         copyrightStr := '┬⌐ 1989,1990 Apple Computer, Inc., v.1.1, by Anup Murarka';
  265.  
  266.         {check that we have the proper number of parameters}
  267.         numParams := paramPtr^.paramCount;
  268.         if (numParams < 1) or (numParams > 2) then
  269.             begin
  270.                 getParams := false;
  271.                 reportToUser(paramPtr, syntaxStr);
  272.                 exit(getParams);
  273.             end;
  274.  
  275.         if AskedForHelp(paramPtr, syntaxStr, copyrightStr) then
  276.             begin
  277.                 getParams := false;
  278.                 exit(getParams);
  279.             end;
  280.  
  281.         { Get first parameter}
  282.         ZeroToPas(paramPtr, paramPtr^.Params[1]^, PathToFile);
  283.  
  284.     end;     {GetParams}
  285.  
  286.     procedure FileCreationDate (paramPtr: XCmdPtr);
  287.         var
  288.             getParamsOK: boolean;
  289.             FileName: str255;
  290.             paramBlock: CInfoPBRec;
  291.             errorCode: OSerr;
  292.  
  293.     begin   { FileCreationDate}
  294.     { fetch and validate the passed parameters}
  295.         getParamsOK := getParams(paramPtr, FileName);
  296.         if not (getParamsOK) then
  297.             exit(FileCreationDate);
  298.  
  299.     { Initialize the parameter block.  Since we have the full pathname,}
  300.     { no other field is really needed.}
  301.         zeroBytes(paramPtr, @paramBlock, sizeOf(paramBlock));
  302.         paramBlock.ioNamePtr := @FileName;
  303.  
  304.         errorCode := PBGetCatInfo(@paramBlock, FALSE);
  305.         if errorCode <> noErr then
  306.             begin
  307.                 reportResError(paramPtr, errorCode);
  308.                 exit(FileCreationDate)
  309.             end;
  310.  
  311.     { Now prepare the return value.  Use FileName as a temp variable}
  312.         FileName := LongToString(paramPtr, paramBlock.ioFlCrDat);
  313.         paramPtr^.returnValue := PasToZero(paramPtr, FileName);
  314.     end;
  315.  
  316. end.